package com.temc.kafka.consumer;

import com.temc.kafka.constant.TopicConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 *
 * @author 辛凤文
 * @since 1.0
 **/
@Slf4j
@Component
public class KafkaNormalConsumer {
    /**
     * 默认获取最后一条消息
     * @param record 该参数可以是任意类型，如常用的String Object Long List等类型，可由Spring自动映射
     *               也可自定义配置
     */
    @KafkaListener(topics = {TopicConstants.TEST}, groupId = "test-group-id")
    public void onMessage(ConsumerRecord<String, String> record) {
        Object key = record.key();
        Object value = record.value();
        String topic = record.topic();
        int partition = record.partition();
        log.info("【消费者】received the message topic {}, partition {}, key {}，value：{}", topic, partition, key, value);
    }


    //@KafkaListener(topics = "test-topic", groupId = "test-group-id")
    //public void listen(String message) {
    //    log.info("【消费者】received the message : {}", message);
    //}

}
